package com.cqeec.crud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cqeec.crud.bean.Emplovee;
import com.cqeec.crud.bean.Msg;
import com.cqeec.crud.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
public class EmployeeController {
	@Autowired
	EmployeeService employeeService;
	/**
	 * 
	 */
	@RequestMapping("/emps")
	@ResponseBody
	public Msg  getEmpsWithJson(@RequestParam(value="pn",defaultValue="1") Integer pn) {
		PageHelper.startPage(pn,5);
		//start
		List<Emplovee> list= employeeService.getAll();   
		PageInfo<Emplovee>  pageInfo = new PageInfo<>(list,5);
		return  Msg.success().add("pageInfo",pageInfo);
	}
	/**
	 * 第一次请求
	 * @param pn
	 * @param model
	 * @return
	 */
	//@RequestMapping("/emps")
	public String getEmps(@RequestParam(value="pn",defaultValue="1")Integer pn,Model model) {
		PageHelper.startPage(pn,5);
		//start
		List<Emplovee> list= employeeService.getAll();   
		PageInfo<Emplovee>  pageInfo = new PageInfo<>(list,5);
		model.addAttribute("pageInfo", pageInfo);
		return "list";
	}  
	@RequestMapping("/emp")
	@ResponseBody
	public String s() {
		System.out.println("你好是");
		return "OK";
	}
}
